home *** CD-ROM | disk | FTP | other *** search
- Path: news.uh.edu!sukku
- From: sukku@menudo.uh.edu (sukumar)
- Newsgroups: comp.lang.c++
- Subject: Dynamic alloc of 2D array??
- Date: 8 Mar 1996 15:22:32 GMT
- Organization: University of Houston
- Message-ID: <4hpjbo$fsb@masala.cc.uh.edu>
- NNTP-Posting-Host: menudo.uh.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- Hi,
- I am trying to allocate a 2D array. This is how I am doing it:
-
- char** cities;
-
-
- // Alloc x number of char*s
- cities = new (char* [x]);
-
-
- // Alloc bytes to each city
- for(i=0; i<x; i++)
- cities[i] = new char[y];
-
-
- ....
-
- I copy a string to each city in some cases
-
- and some times all the cities are not assigned any strings
-
-
- ....
-
-
- for(i=0; i<x; i++)
- delete [] cities[i];
- delete [] cities;
-
-
-
- The program crashes when I don't assign anything to the cities.
- What is the right way to alloc an array of pointers and delete them??
-
-
- TIA,
- SK
-